**************************************************
*Trade shock effects on exports and # of products*
**************************************************
* GENERATES TABLE  2 in paper
*
use temp,clear
eststo clear
keep if nbnc8iso2>1
keep if nbnc8_max>1
keep if theil_d1 !=.
*same sample as later
gen lexport_int_d1 = lexport_d1 - lnbnc8iso2_d1
global depvar_d1 = "lexport_int_d1"
global nbnc8iso2_d1 "lnbnc8iso2_d1"
egen isiciso = group(isic iso2_d)
*
*FD
global clustvar "iso2_d"
eststo: reg $depvar_d1 lgdpshock6   yd* , robust cluster($clustvar)
global clustvar "firmiso"
eststo: reg $depvar_d1 ltradeshock6  yd* , robust cluster($clustvar)
global clustvar "isiciso"
eststo: reg $depvar_d1 ltradeshock6i yd* , robust cluster($clustvar)
*
global clustvar "iso2_d"
eststo: reg $nbnc8iso2_d1 lgdpshock6   yd* , robust cluster($clustvar)
global clustvar "firmiso"
eststo: reg $nbnc8iso2_d1 ltradeshock6  yd* , robust cluster($clustvar)
global clustvar "isiciso"
eststo: reg $nbnc8iso2_d1 ltradeshock6i yd* , robust cluster($clustvar)
*
log using $DIRLOG/Replication/tab-demandlocalexports.txt, text replace
set linesize 250
esttab, drop(yd* ) b(%4.3f) se(%4.3f) r2 starlevels({$^c$} 0.1 {$^b$} 0.05 {$^a$} 0.01)  tex  title() label
esttab, drop(yd* ) compress r2 starlevels(c 0.1 b 0.05 a 0.01)  b(%4.3f) se(%4.3f)
*output the results in a tex file directly inputable in the text
esttab using $DIRLOG/Replication/tab-demandlocalexports_input.tex, b(%4.3f) se(%4.3f)  starlevels({$^c$} 0.1 {$^b$} 0.05 {$^a$} 0.01)    ///
nocons drop(yd* _cons )  label tex substitute(\_ _) fragment replace nodepvars nonumbers nomtitles nogaps nolines eqlabels(none)
eststo clear
*all variables together
reg $depvar_d1 lgdpshock6 ltradeshock6 ltradeshock6i yd* , robust cluster(iso2_d)
reg $nbnc8iso2_d1 lgdpshock6 ltradeshock6 ltradeshock6i yd* , robust cluster(iso2_d)
*
log close
*
label var lnbnc8iso2_d1 "d ln count of products"
label var lexport_d1 "d ln export value"
label var ltradeshock6 " trade shock "
*
* Robustness with leads and lags
*
use temp,clear
eststo clear
keep if nbnc8iso2>1
keep if nbnc8_max>1
keep if theil_d1 !=.
*same sample as later
gen lexport_int_d1 = lexport_d1 - lnbnc8iso2_d1
global depvar_d1 = "lexport_int_d1"
global nbnc8iso2_d1 "lnbnc8iso2_d1"
egen isiciso = group(isic iso2_d)
*
*FD
global clustvar "iso2_d"
eststo: reg $depvar_d1 lgdpshock6_l2 lgdpshock6_l1 lgdpshock6  lgdpshock6_f1 lgdpshock6_f2  yd* , robust cluster($clustvar)
global clustvar "firmiso"
eststo: reg $depvar_d1 ltradeshock6_l2 ltradeshock6_l1 ltradeshock6 ltradeshock6_f1 ltradeshock6_f2  yd* , robust cluster($clustvar)
global clustvar "isiciso"
eststo: reg $depvar_d1 ltradeshock6i_l2 ltradeshock6i_l1 ltradeshock6i ltradeshock6i_f1 ltradeshock6i_f2 yd* , robust cluster($clustvar)
*
global clustvar "iso2_d"
eststo: reg $nbnc8iso2_d1 lgdpshock6_l2 lgdpshock6_l1 lgdpshock6  lgdpshock6_f1 lgdpshock6_f2    yd* , robust cluster($clustvar)
global clustvar "firmiso"
eststo: reg $nbnc8iso2_d1 ltradeshock6_l2 ltradeshock6_l1 ltradeshock6 ltradeshock6_f1 ltradeshock6_f2   yd* , robust cluster($clustvar)
global clustvar "isiciso"
eststo: reg $nbnc8iso2_d1 ltradeshock6i_l2 ltradeshock6i_l1 ltradeshock6i ltradeshock6i_f1 ltradeshock6i_f2 yd* , robust cluster($clustvar)
*
log using $DIRLOG/Replication/tab-demandlocalexports_robleadlag.txt, text replace
set linesize 250
esttab, drop(yd* ) b(%4.3f) se(%4.3f) r2 starlevels({$^c$} 0.1 {$^b$} 0.05 {$^a$} 0.01)  tex  title() label
esttab, drop(yd* ) compress r2 starlevels(c 0.1 b 0.05 a 0.01)  b(%4.3f) se(%4.3f)
*output the results in a tex file directly inputable in the text
esttab using $DIRLOG/Replication/tab-demandlocalexports_robleadlag_input.tex, b(%4.3f) se(%4.3f)  starlevels({$^c$} 0.1 {$^b$} 0.05 {$^a$} 0.01)    ///
nocons drop(yd* _cons )  label tex substitute(\_ _) fragment replace nodepvars nonumbers nomtitles nogaps nolines eqlabels(none)
eststo clear
*
log close
